<?php
/*
 *  supplier 供货商添加类
 *
 *  @param $c 一般是类名
 *  @param $a 一般是方法名
 */
class comment extends goodsSaler {

    public function index( $c, $a ) {



        $this->table = 'evaluate';
        $this->pk = 'id';
        $result = $this->Paged()->findAll( );
        $pager = $result[ 'page' ];
        $result = $result[ 'result' ];

        include $this->display( $c ); // 加载模板


    }

    public function search($c,$a)
    {
        $this->table = 'evaluate';

        $where = array( G( 'k' ) => G( 'v' ) );
        if ( $key = G( 'key' ) ) {
            $tmp = '';
            foreach ( $where as $k => $v ) {
                $tmp .= "{$k}='" . urldecode( $v ) . "' and ";
            }
            $where = $tmp ? ( $tmp . "wwId ={$key} " ) : '';
        }

        $this->pk = 'id';
        $result = $this->Paged()->findAll( $where );
        $pager = $result[ 'page' ];
        $result = $result[ 'result' ];

       $statics['total'] =  count($result);
        $res = $this->Paged()->findAll( $where." and type = 1" );
        print_r($res);
       $statics['goodComment'] =count( $res['result']);
        $res = $this->Paged()->findAll( $where."and type = 2" );
       $statics['badComment'] = count($res['result']);

        print_r($statics['goodComment']);



        include $this->display( $c ); // 加载模板

    }

    public function look( $c, $a ) {
        if ( !$id = intval( G( 'id' ) ) ) {
            $this->error();
            exit;
        }

        $this->table = 'evaluate'; // 数据库表名
        $result = $this->find( array( 'id' => $id ) ); // 查找数据
        include $this->display( $c ); // 加载模板
    }

    public function add( $c, $a ) {
        include $this->display( $c );
    }

    public function save() {
        # 获取表单数据
        foreach ( $_POST as $key => $val ) {
            $rows[ $key ] = htmlspecialchars( trim( $val ) );
        }

        # 注意 表单字段必须跟数据库表字段名一样
        $this->table = ''; // 数据库表名
        if ( $id = intval( G( "id" ) ) ) {
            $msg = $this->update( array( 'id' => $id ), $rows ) ? 'success' : 'failed';  //更新供货商
        } else {
            $msg = $this->create( $rows ) ? 'success' : 'failed';                         // 添加供货商
        }
        exit( $msg );
    }
}
?>